<!--
 * @Author: your name
 * @Date: 2021-08-16 17:40:41
 * @LastEditTime: 2021-08-25 17:49:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \orderSystems\src\views\menuMag\search.vue
-->
<template>
  <!-- 搜索组件 -->
  <div id="search">
    <div class="search-container">
      <div class="search-title">查询</div>
      <el-form :inline="true" :model="formInline" class="form-search">
        <el-form-item label="搜索：" class="search-item">
          <el-input
            clearable
            v-model="formInline.search"
            placeholder="可以根据菜名进行搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="筛选" class="search-item">
          <el-select v-model="valueId" clearable  placeholder="可以根据菜品类别进行删选">
            <el-option 
            v-for="item in selectchoice" 
            :key="item.id"
            :label="item.category" 
            :value="item.id ">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="search-item">
          <el-button type="success" icon="el-icon-search" @click="onSearch"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        search: "", //要搜索的菜名
      },
      valueId:"",//筛选类别的id
      selectchoice:[],//存储下拉列表数据的数组
      page:1,
      pageSize:5,
      tableData:[],//查询到的数据数组
      totalCount:[],//查询到的总数据
      valueId:'',//查询菜品类别对应的id
      name:'',//查询的菜品名
      searchFlag:false,//查询的标准变量
      
    };
  },
  created(){
    //渲染筛选的下拉列表
    this.choiceSelect();
  },
  methods: {
    //点击搜索的函数
    async onSearch() {
      const {data:res}=await this.axios.post("/dishFile/list",{
        categoryName:this.valueId,//菜品类别对应的id
        name:this.formInline.search//菜品名
      })
      // console.log('查询的类别',res.data);
      if(res.code==200){
        console.log('查询到的数据总数',res.count);
        // console.log("查询的数据",res.data);
        // console.log('valueId',this.valueId);
        // console.log('name',this.name);
        this.tableData=res.data;
        this.totalCount=res.count;
        this.searchFlag=true;
        this.$emit('shareSearchStatus',{
          tableData:this.tableData,
          totalCount:this.totalCount,
          searchFlag:this.searchFlag,
          name:this.formInline.search,
          valueId:this.valueId
        })

      }
    },
  /**
   * @description: 搜索的筛选框的下拉列表
   * @param {*}
   * @return {*}
   */   
  async choiceSelect(){
    const {data:res}=await this.axios.post("/dishesCategory/findCategory");
    if(res.code==200){
      // console.log('菜品类别',res.data);
      this.selectchoice=res.data;
    }
  } 
  },
};
</script>

<style lang='less' scoped>
.search-container {
  background-color: #fff;
  //   height: 8rem;
  border: 0.1rem solid #dbe0e9;
  .search-title {
    height: 4rem;
    background-color: #f2f2f2;
    box-sizing: border-box;
    border-bottom: 0.1rem solid #dbe0e9;
    line-height: 4rem;
    font-size: 1.4rem;
    padding-left: 3rem;
    font-weight: 500;
    color: #666666;
  }
  .form-search {
    margin: 1rem;
    padding: 1.5rem;
    background-color: #f5f9fc;
    box-sizing: border-box;
    .search-item {
      margin-bottom: 0;
    }
  }
}
</style>